package com.atwisdom.star.controller.customized;

import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.common.vo.JsonResult;
import com.atwisdom.star.common.vo.ResultInfo;
import com.atwisdom.star.core.bsl.customized.StockBslService;
import com.atwisdom.star.exception.pojo.BusinessException;
import com.atwisdom.star.log.aop.StarAnnotation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@AllArgsConstructor
@RequestMapping("/stock")
public class StockController {
    private StockBslService stockBslService;

    /**
     * 通过bcode与quantity，确定可以出库的记录
     * @return 返回结果
     */
    @PostMapping(value = "/availableStockDetail")
    public ResultInfo<?> queryAvailableStockDetail(@RequestBody JSONObject dataJson) {
        List<JSONObject> resultList = stockBslService.queryAvailableStockDetail(dataJson);
        return JsonResult.success(resultList);
    }

    /**
     * 通过bcode与quantity，kanbancode 确定看板号是否可以出库
     * @return 返回结果
     */
    @PostMapping(value = "/predicateBoard")
    public ResultInfo<?> predicateBoard(@RequestBody JSONObject dataJson) {
        JSONObject b = stockBslService.predicateBoard(dataJson);
        return JsonResult.success(b);
    }

    /**
     * 通过bcode与quantity，确定可以出库的记录
     * @return 返回结果
     */
    @PostMapping(value = "/queryByBinCode")
    public ResultInfo<?> queryByBinCode(@RequestBody JSONObject dataJson) {
        List<JSONObject> resultList = stockBslService.queryByBinId(dataJson);
        return JsonResult.success(resultList);
    }

    /**
     * 出库
     * @return 返回结果
     */
    @PostMapping(value = "/outBound")
    public ResultInfo<?> outBound(@RequestBody JSONObject dataJson) {
        List<JSONObject> result = stockBslService.outBound(dataJson);
        return JsonResult.success(result);
    }

    /**
     * 强制出库
     * @return 返回结果
     */
    @PostMapping(value = "/outBoundForce")
    public ResultInfo<?> outBoundForce(@RequestBody JSONObject dataJson) {
        List<JSONObject> result = stockBslService.outBoundForce(dataJson);
        return JsonResult.success(result);
    }

    /**
     * 强制出库
     * @return 返回结果
     */
    @PostMapping(value = "/inBound")
    public ResultInfo<?> inBound(@RequestBody JSONObject dataJson) {
        stockBslService.inBound(dataJson);
        return JsonResult.success();
    }

}
